#!/bin/bash

source  /etc/profile

if [ -n "$1" ]
then
  do_date=$1
else
  do_date=`date -d "-1 day" +%F`
fi

# 定义要执行的sql
sql="
-- 获取站点每日的营收统计
insert overwrite table dws.dws_station_income_day
partition(dt='$do_date')
select
a.target_type,
a.station_id,
b.name as station_name,
c.id as org_id,
c.name as org_name,
d.id as operator_id,
d.name as operator_name,
sum(a.money) as income
from
dwd.dwd_clearing_order_item a
left join
dim.dim_station b
on a.station_id = b.id
left join
dim.dim_org c
on b.org_id = c.id
left join
dim.dim_operator d
on c.operator_id = d.id
where dt='$do_date'
group by station_id, target_type;

-- 获取站点每月的营收统计

insert overwrite table dws.dws_station_income_day
partition(dt='$do_date')
select
target_type, station_id, sum(money) as income
from
dwd.dwd_clearing_order_item
where dt='$do_date'
group by station_id, target_type;
"

orgSql="
insert overwrite table ads.ads_org_income_day
partition(dt='$do_date')
-- 获取小区每日的营收统计
select
sum(income) as income,
org_id,
org_name
from dws.dws_station_income_day
where dt='$do_date'
group by org_id, org_name
"